/**
 * <b>项目名：</b>hclv-web<br/>  
 * <b>包名：</b>com.flea.hclv.controller<br/>  
 * <b>文件名：</b>HotelPolicyController.java<br/>  
 * <b>版本信息：</b>1.0<br/>  
 * <b>日期：</b>2018年9月16日 下午7:18:22<br/>  
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.constant.HConstant;
import com.flea.hclv.model.entity.HotelPolicy;
import com.flea.hclv.service.HotelPolicyService;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.platform.session.FleaOrgUtils;
import com.flea.system.utils.ControllerResult;

/**
 * @description
 * @createTime 2018年9月16日 下午7:18:22
 * @modifyTime 
 * @author myflea@163.com
 * @version 1.0
 */
@Controller
@RequestMapping("/flea/hclv/hotel/policy")
public class HotelPolicyController {
	@Autowired
	private HotelPolicyService hotelPolicyService;
	@RequestMapping("/saveOrUpdatePolicy")
	public void saveOrUpdatePolicy(HttpServletRequest request,HttpServletResponse response){
		String hotelJSON = request.getParameter("model");

		String userId = FleaOrgUtils.getCurUserUuid(request);
		HotelPolicy hotelPolicy = JSON.parseObject(hotelJSON, HotelPolicy.class);
		
		boolean result =hotelPolicyService.saveOrUpdate(userId,hotelPolicy);

		

		ControllerResult cResult = new ControllerResult(result, "操作成功", result);

		cResult.WriteToPage(response);
	}
	@RequestMapping("/queryAllForPageByOrg")
	public void queryAll(HttpServletRequest request, FleaPage<HotelPolicy> paging,
			HttpServletResponse response) {
		String userId = FleaOrgUtils.getCurUserUuid(request);

		
		String queryName = request.getParameter("queryName");
		String queryLevel = request.getParameter("queryLevel");
		String queryProvince = request.getParameter("queryProvince");
		String queryCity = request.getParameter("queryCity");
		String queryZone = request.getParameter("queryZone");
		OrgDept org =  FleaOrgUtils.getCurrentUserDept(userId);
		
		String orgId =org==null?HConstant.HCLV_ADMIN_ADMIN:org.getDeptUuid();
		FleaPage<HotelPolicy> pageList = hotelPolicyService.findForGirdByOrgId(queryName,
				queryLevel, queryProvince, queryCity, queryZone,
				paging.getCurPage(), paging.getPageSize(),orgId);

		ControllerResult conresult = new ControllerResult(pageList);
		conresult.set(true, "操作成功");

		conresult.WritePagingDataToPage(response, pageList);

	}
	@RequestMapping("/queryAllForPage")
	public void queryAllForPage(HttpServletRequest request, FleaPage<HotelPolicy> paging,
			HttpServletResponse response) {
		
		String queryName = "";
		String queryLevel = "";
		String queryProvince = "";
		String queryCity = "";
		String queryZone = "";
		
		FleaPage<HotelPolicy> pageList = hotelPolicyService.findForGird(queryName,
				queryLevel, queryProvince, queryCity, queryZone,
				paging.getCurPage(), paging.getPageSize());
		
		ControllerResult conresult = new ControllerResult(pageList);
		conresult.set(true, "操作成功");
		
		conresult.WritePagingDataToPage(response, pageList);
		
	}
	@RequestMapping("deletByIds")
	public void deletHotel(HttpServletRequest request,
			@Param("ids") String ids, HttpServletResponse response) {

		String userId = FleaOrgUtils.getCurUserUuid(request);
		boolean result = hotelPolicyService.deleteByIds(ids, userId);

		ControllerResult cResult = new ControllerResult(result,
				result == true ? "操作成功" : "操作失败", result);
		cResult.WriteToPage(response);
	}
}
